package htmlCanvas;

import context.*;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class HtmlTokenizer implements Debug.Constants
{ //private static final boolean DEBUG=true; // Overriding Debug.Constants.DEBUG
  private int pos=0;
  private byte[] bytes;
  
  public HtmlTokenizer(String input)
  {
    //Debug.println("Tokenizer: new Tokenizer(\""+input+"\")");
    this.bytes=input.getBytes();
  }
  
  public HtmlTokenizer(byte[] bytes)
  {
    //Debug.println("Tokenizer: new Tokenizer(\""+new String(bytes)+"\")");
    this.bytes=bytes;
  }
  
  // Scan until <code>sep</code> or end of stream
  // Returns empty string if no more
  public String next()
  { StringBuffer buf=new StringBuffer();
//    Debug.println("Tokenizer.next()");
    try
    { // Skip whitespaces
      while(isWhitespace(bytes[pos])) pos++;
      while(!isWhitespace(bytes[pos])) buf.append((char)bytes[pos++]);
    } catch(Exception e) {}
//    Debug.println("Tokenizer.next() --> \""+buf.toString()+"\"");
    return(buf.toString());
  }
  
  private boolean isWhitespace(byte b)
  { switch(b)
	{ case ' ': case '\r': case '\n': case '\t': return(true); }
	return(false);
  }
  
}
